"""
@author: zjc
@file: musicinfo.py
@time: 2023/3/5 20:11
"""
from model import db
from model.userdb.userinfo import User

# 歌曲信息
class Music(db.Model):
    __tablename__ = "music"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    music_name = db.Column(db.String(128), nullable=False)
    music_path=db.Column(db.String(80),nullable=False)
    lyric_path=db.Column(db.String(80),nullable=False)
    priase_len=db.Column(db.INT,nullable=False)
    poster=db.Column(db.String(255),nullable=False)
    singer_id=db.Column(db.Integer,db.ForeignKey("singer.id"))
    singer=db.relationship('Singer',backref=db.backref('musics'))

    def key(self):
        return ('id','music_name','music_path','lyric_path',' priase_len',
                'poster')

    def __getitem__(self, item):
        return getattr(self,item)


# 歌手信息
class Singer(db.Model):
    __tablename__ = "singer"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    sg_name=db.Column(db.String(40),nullable=False)
    sg_sex=db.Column(db.String(40),nullable=False)

    def key(self):
        return  ('id','sg_name','sg_sex')

    def __getitem__(self, item):
        return getattr(self,item)


# 歌单表
class Songs_Menu(db.Model):
    __tablename__ = "songmenu"
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    songm_name=db.Column(db.String(255),nullable=False)
    music_id=db.Column(db.ForeignKey("music.id"),nullable=False)
    musicinfo=db.relationship('Music',backref=db.backref('song_menus'))
    user_id=db.Column(db.ForeignKey("userinfo.id"),nullable=False)
    userinfo=db.relationship('User',backref=db.backref('song_menus'))

    def key(self):
        return ('id','songm_name')

    def __getitem__(self, item):
        return getattr(self,item)


